package com.myhome.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.myhome.entity.AdminRole;
import com.myhome.entity.RespBean;
import com.myhome.mapper.AdminRoleMapper;
import com.myhome.service.IAdminRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jobob
 * @since 2021-09-04
 */
@Service
@Transactional
public class AdminRoleServiceImpl extends ServiceImpl<AdminRoleMapper, AdminRole> implements IAdminRoleService {

    @Autowired
    AdminRoleMapper adminRoleMapper;

    @Override
    public RespBean updateAdminRoles(Integer adminId, Integer[] ids) {
        adminRoleMapper.delete(new QueryWrapper<AdminRole>().eq("adminId", adminId));
        if (0 == ids.length || null == ids) {
            return RespBean.success("修改成功");
        }
        Integer result = adminRoleMapper.addAdminRolse(adminId, ids);
        if (result == ids.length) {
            return RespBean.success("修改成功");
        }
        return RespBean.error("修改失败");
    }
}
